package mpYoga

import (
	"duoke/model/yogaModel"
	yogaService "duoke/service/yoga"
	"duoke/utils/response"
	"duoke/utils/valid"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/go-playground/validator/v10"
)

var GroupClass = new(groupClassCtl)

type groupClassCtl struct{}

func (ctl *groupClassCtl) List(c *gin.Context) {
	var req yogaModel.SearchGroupClass
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, valid.GetError(err.(validator.ValidationErrors), req), nil)
		return
	}
	list, count, err := yogaService.GroupClass.List(c, req)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", gin.H{"total": count, "list": list})
}
func (ctl *groupClassCtl) HotList(c *gin.Context) {
	var req yogaModel.ReqHotList
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, valid.GetError(err.(validator.ValidationErrors), req), nil)
		return
	}
	where := fmt.Sprintf("yc.venue_id = %d and class_type=%d and is_hot=1",
		req.FromId, req.ClassType)
	list, count, err := yogaService.GroupClass.HotList(c, &req, where)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", gin.H{"total": count, "list": list})
}
func (ctl *groupClassCtl) Info(c *gin.Context) {
	var req yogaModel.RspClassTime
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, valid.GetError(err.(validator.ValidationErrors), req), nil)
		return
	}
	info, err := yogaService.GroupClass.Info(c, &req)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", info)
}
func (ctl *groupClassCtl) Infos(c *gin.Context) {
	var req yogaModel.SearchSchoolTimetable
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, valid.GetError(err.(validator.ValidationErrors), req), nil)
		return
	}
	info, err := yogaService.GroupClass.Infos(c, &req)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", info)
}

func (ctl *groupClassCtl) TeacherList(c *gin.Context) {
	var req yogaModel.ReqHotList
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, valid.GetError(err.(validator.ValidationErrors), req), nil)
		return
	}
	where := fmt.Sprintf("yc.teacher_id = %d and class_type=%d and is_hot=1",
		req.FromId, req.ClassType)
	list, count, err := yogaService.GroupClass.HotList(c, &req, where)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", gin.H{"total": count, "list": list})
}
